import { NextRequest, NextResponse } from 'next/server';
import { PeriodService } from '@/services/periodService';

export async function PUT(
  request: NextRequest,
  { params }: { params: { id: string } }
) {
  try {
    const data = await request.json();
    const period = await PeriodService.updatePeriod(params.id, {
      end_date: data.end_date ? new Date(data.end_date) : undefined,
    });

    return NextResponse.json({ code: 200, data: period });
  } catch (error) {
    console.error('PUT period error:', error);
    return NextResponse.json(
      { code: 500, error: '更新经期记录失败' },
      { status: 500 }
    );
  }
}

export async function DELETE(
  request: NextRequest,
  { params }: { params: { id: string } }
) {
  try {
    await PeriodService.deletePeriod(params.id);
    return NextResponse.json({ 
      code: 200, 
      message: '删除成功' 
    });
  } catch (error) {
    console.error('DELETE period error:', error);
    return NextResponse.json(
      { code: 500, error: '删除经期记录失败' },
      { status: 500 }
    );
  }
} 